package com.globalLogic.gps.view;

import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;

import com.globalLogic.gps.graph.Graph;

public class GPSView extends JFrame {

	private static final long serialVersionUID = 1L;
	private List<NodeView> nodosVista = new ArrayList<NodeView>();
	private static int ALTO = 400;
	private static int ANCHO = 500;
	private Graph graph;

	public GPSView(Graph pGraph) {
		super("Dibujo de GPS");
		setSize(ANCHO, ALTO);
		setVisible(true);
		graph = pGraph;
	}

	public void paint(Graphics g) {
		super.paint(g);
		int x = 200;
		int y = 200;
		int ancho = 30;
		int alto = 30;
		int radio = 150;
		float angulo = 360 / 10;
		angulo = (float) Math.toRadians(angulo);
		for (int i = 0; i < graph.getNodes().length; i++) {
			
			int xv = (int) (x + radio * Math.cos(i * angulo));
			int yv = (int) (y - radio * Math.sin(i * angulo));
			NodeView nodo = new NodeView(graph.getNodes()[i], xv, yv);
			nodosVista.add(nodo);
			g.setColor(Color.BLACK);
			g.drawOval(nodo.getX(), nodo.getY(), ancho, alto);
			g.drawString("" + graph.getNodes()[i].getId(), nodo.getX()
					+ ((ancho / 2) - 3), nodo.getY() + ((alto / 2) + 3));
		}

		for (NodeView origen : nodosVista) {
			for (NodeView destino : nodosVista) {
				if (origen.getNode().getId() != destino.getNode().getId()) {
					int d = this.graph.distanceBetweenNodes(origen.getNode()
							.getId(), destino.getNode().getId());
					if (d != 0) {

						g.drawLine(origen.getX() + 15, origen.getY() + 15,
								destino.getX() + 15, destino.getY() + 15);
						this.getGraphics().drawString("" + d,
								(origen.getX() + destino.getX() + 30) / 2,
								(origen.getY() + destino.getY() + 30) / 2);

					}
				}
			}
		}

	}


}